<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/3/10
 * Time: 11:27
 */

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Request;

class Prop extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';


    /**
     * 商城道具
     */
    public function prop()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        if(!$type=  input('type'))
        {
            $this->error('缺少参数');
        }
        $limit = input('get.limit',10);
        $where = [];
        $where['status']= 1;
        if($type==1)
        {
            $where['recommend'] = 1;
        }

        $list = Db::name('prop')->field('id,title,service_tems,price,old_price,image')->where($where)->order('id','desc')->limit($limit)->select();
        if(!$list)
            $this->error('暂无数据');
        $this->success('',$list);
    }



    /**
     * 列表
     */
    public function list()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        $page = input('get.page',1);
        $limit = input('get.limit',10);
        $where = [];
        $where['status']=1;
        if($title=input('get.title'))
        {
            $where['title']=['like','%'.$title.'%'];
        }
        $list = Db::name('prop')->field('id,title,service_tems,price,old_price,image')->where($where)->order('id','desc')->paginate($limit,'',['page'=>$page]);
        if(!$list)
            $this->error('暂无数据');
        $this->success('',$list);
    }

    public function detail()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        if(!$id = input('get.id'))
        {
            $this->error('缺少参数');
        }

        $info = Db::name('prop')->field('id,title,service_tems,specification,price,old_price,image,details,image')->where('id',$id)->find();
        if(!$info)
            $this->error('暂无数据');
        $this->success('',$info);

    }
}